package com.hp.appfw.service.cust;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.hp.appfw.data.mode.mygen.BaseMessageLog;
import com.hp.appfw.data.mode.mygen.BaseMessageMission;

@Service("pushMessageService")
public class PushMessageService {
	
	@Resource
	MessageCenterService messageService;

	public void pushTextMessage(String entId, String title, String summary, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "text");
		keys.put("orgId", "");
		keys.put("courseId", "");
		keys.put("contentId", "");
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", "");
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String userId : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(userId);
				log.setRecieverId(userId);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void pushKnowMessage(String entId, String title, String summary, String orgId, String courseId, String knowId, String status, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "know");
		keys.put("orgId", orgId);
		keys.put("courseId", courseId);
		keys.put("contentId", knowId);
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", status);
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String userId : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(userId);
				log.setRecieverId(userId);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void pushRecomMessage(String entId, String title, String summary, String orgId, String knowId, String status, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "recom");
		keys.put("orgId", orgId);
		keys.put("courseId", "");
		keys.put("contentId", knowId);
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", status);
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String userId : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(userId);
				log.setRecieverId(userId);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void pushSurveyMessage(String entId, String title, String summary, String orgId, String courseId, String surveyId, String status, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "survey");
		keys.put("orgId", orgId);
		keys.put("courseId", courseId);
		keys.put("contentId", surveyId);
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", status);
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String userId : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(userId);
				log.setRecieverId(userId);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void pushQuizMessage(String entId, String title, String summary, String orgId, String courseId, String quizId, String status, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "quiz");
		keys.put("orgId", orgId);
		keys.put("courseId", courseId);
		keys.put("contentId", quizId);
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", status);
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String userId : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(userId);
				log.setRecieverId(userId);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void pushQaNewReplyMessage(String entId, String title, String summary, String orgId, String courseId, String questionId, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "qaNewReply");
		keys.put("orgId", orgId);
		keys.put("courseId", courseId);
		keys.put("contentId", questionId);
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", "");
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String userId : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(userId);
				log.setRecieverId(userId);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void pushLotteryMessage(String entId, String title, String summary, String orgId, String courseId, String userId, String extra, List<String> userIdList)
	{
		HashMap<String, String> keys = new HashMap<String, String>();
		keys.put("msgId", "${param.item.log.id}");
		keys.put("entId", entId);
		keys.put("type", "lottery");
		keys.put("orgId", orgId);
		keys.put("courseId", courseId);
		keys.put("contentId", userId);
		keys.put("title", title);
		keys.put("summary", summary);
		keys.put("status", "");
		keys.put("extra", extra);
		
		try {
			BaseMessageMission mission = messageService.createTerminalMission(title, keys, entId);
			List<BaseMessageLog> logList = new ArrayList<BaseMessageLog>();
			for(String uid : userIdList)
			{
				BaseMessageLog log = new BaseMessageLog();
				log.setMissionId(mission.getId());
				log.setReciever(uid);
				log.setRecieverId(uid);
				log.setSenderId("system");
				log.setType("Terminal");
				log.setParam("<none/>");
				logList.add(log);
			}
			
			messageService.sendMassMessage(mission, logList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
